package tgc.edu.exam.custom;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

public class ImageeditUtils {

	/****
	 * 
	 * @param backgroundPath 背景图片路径
	 * @param qrCodePath 插入图片的路径
	 * @param message01 消息
	 * @param message02
	 * @param outPutPath 输出图片的路径
	 * @return
	 */
	 public static String overlapImage(String backgroundPath,String message01,String message02,String message03,String message04,String outPutPath){
	        try {
	            //设置图片大小
//	            BufferedImage background = resizeImage(618,1000, ImageIO.read(new File("这里是背景图片的路径！")));
	            BufferedImage background = resizeImage(1000,618, ImageIO.read(new File(backgroundPath)));
//	            BufferedImage qrCode = resizeImage(150,150,ImageIO.read(new File("这里是插入二维码图片的路径！")));
	            //BufferedImage qrCode = resizeImage(150,150,ImageIO.read(new File(qrCodePath)));
	            //在背景图片中添加入需要写入的信息，例如：扫描下方二维码，欢迎大家添加我的淘宝返利机器人，居家必备，省钱购物专属小秘书！
	            //String message = "扫描下方二维码，欢迎大家添加我的淘宝返利机器人，居家必备，省钱购物专属小秘书！";
	            Graphics2D g = background.createGraphics();
	            g.setColor(Color.black);
	            g.setFont(new Font("楷体",Font.BOLD,18));
	            g.drawString(message01,323 ,265);
	            g.drawString(message02,470 ,265);
	            g.drawString(message03,680 ,265);
	            g.drawString(message04,555 ,310);
	            //在背景图片上添加二维码图片
	            //g.drawImage(qrCode, 700, 240, qrCode.getWidth(), qrCode.getHeight(), null);
	            g.dispose();
//	            ImageIO.write(background, "jpg", new File("这里是一个输出图片的路径"));
	            ImageIO.write(background, "jpg", new File(outPutPath));
	        }catch (Exception e){
	            e.printStackTrace();
	        }
	        return null;
	    }
	 
	    public static BufferedImage resizeImage(int x, int y, BufferedImage bfi){
	        BufferedImage bufferedImage = new BufferedImage(x, y, BufferedImage.TYPE_INT_RGB);
	        bufferedImage.getGraphics().drawImage(
	                bfi.getScaledInstance(x, y, Image.SCALE_SMOOTH), 0, 0, null);
	        return bufferedImage;
	    }
}
